﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.ObjectModel;
using client.Managers.Connection;
using System.Threading;

namespace client
{
    
    /// <summary>
    /// This is a TaskbarNotifier that contains a list of NotifyObjects to be displayed.
    /// </summary>
    public partial class TaskbarNotifierWindow : TaskbarNotifier
    {
        private string title;
        private string message;
        public TaskbarNotifierWindow(string titl, string messag)
        {
            InitializeComponent();
            Publisher.Instance.AddListener(ShowNotification);
            title = titl;
            message = messag;
        }
        public TaskbarNotifierWindow()
        {
            InitializeComponent();
            Publisher.Instance.AddListener(ShowNotification);
        }

        private void HideButton_Click(object sender, EventArgs e)
        {
            this.ForceHidden();
        }

        private void ThisControl_Loaded(object sender, RoutedEventArgs e)
        {
            titleLable.Content = title;
            richTextBox1.Document.Blocks.Clear();
            richTextBox1.AppendText(message.ToString());
        }

        protected void ShowNotification(object sender, AlertsPublisherEventArgs args)
        {
            this.Dispatcher.Invoke((ThreadStart)delegate
            {
                title = args.Alerts[0].NotificationDescription.alert_type;
                message = args.Alerts[0].NotificationDescription.notification;
                this.Show();
                this.Notify();
            });
        }
    }
}